Countdown Timer
In-game description The timer executes a line or set of lines when the amount of time specified has passed. Immediately after you place timer, you’ll want to place a number to specify how long the countdown is. The game interprets this number as being in seconds, although you can add a modifier frames afterwards to change that. Use It’s important to realize that lines governed by timer will run continually after the time specified is elapsed. That means that a simple WHEN timer 5 DO jump is placed, the brain will wait 5 seconds then jump, jump, jump etc. (continually). You can, however, introduce more interesting behaviors by utilizing the modifiers hold and loop. Check those tiles out after you've placed timer in your line! You can also use the logic tiles like to, longer, until or after with the countdown timers. For example, WHEN to timer number will only execute once the number of seconds elapse (and only once). This tile must have a number as a parameter. If no number is specified, it defaults to 1. This number is measured in seconds unless the frames tile is present (note that there are 30 frames in a second). Modifiers * Hold: Pauses a completed timer for a specified amount of time. * Loop: Tells a timer to start over once it has completed. Examples Example: Time bomb This tells the brain: after 3 seconds, destroy self. Example: Church Bell This tells the brain: After 3 seconds, play the "bell" sound and then loop. That means that it will play the sound every 3 seconds, starting with a 3 second delay. Advanced Modifiers * Tells the timer to measure in frames of game time instead of seconds. This is particularly useful when you want to count less than a second easily or loop something really fast. Project Spark framerate is 30 frames per second (FPS). * Triggers the action to run immediately, and then begin the timer. Advanced Examples Example: The Telephone Ring Taking the Church bell example from above and adding a few more tiles we can create a more complex mechanism that will make the sound of the bell look like a telephone ring. Here is how: What this will do is tell the brain to play continually the bell sound for one second (30 frames), then wait one second and then loop. The sound will start immediately, because we entered the on start tile. So, this will simulate a telephone ring (try it for yourself with different sounds for better results). Outputs * The number of seconds that the timer will remain on or off. *The number of seconds that the timer has been on or off. *The ratio of time that the timer will remain on or off. * The ratio of time that the timer has been on or off. Output examples Example: Displaying a countdown timer on screen Using the outputs will always display the figure with four decimals. To avoid that, simply use the round function, as seen in this example. This brain will display on screen a countdown timer from 100. In order to do this, we used a number variable, called "Timer variable" to hold the rounded seconds and then display them.. Category:Brains